package com.hurl.library.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	  public static final long MILLIS_PER_SECOND = 1000L;
	  public static final long MILLIS_PER_MINUTE = 60000L;
	  public static final long MILLIS_PER_HOUR = 3600000L;
	  public static final long MILLIS_PER_DAY = 86400000L;
	  public static final long MILLIS_PER_WEEK = 86400000L*7;
	  
	public static final String FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
	public static final String FORMAT_DATE = "yyyy-MM-dd";
	
	/**
	 * 获取今天的日期，只包含年、月、日的信息，不包含时、分、秒的信息。
	 * @return
	 */
	public static Date getDate(Date date){
		SimpleDateFormat formatter = new SimpleDateFormat (FORMAT_DATE);
		try {
			return formatter.parse(formatter.format(date));
		} catch (ParseException e) {
			e.printStackTrace();
			throw new RuntimeException("转换日期时遇到格式错误！",e);
		}
	}
	public static Date getDateTime(Date date){
		SimpleDateFormat formatter = new SimpleDateFormat (FORMAT_DATE);
		try {
			return formatter.parse(formatter.format(date));
		} catch (ParseException e) {
			e.printStackTrace();
			throw new RuntimeException("转换日期时遇到格式错误！",e);
		}
	}
	public static Date parseDate(String dateString, String format) throws ParseException{
		SimpleDateFormat formatter = new SimpleDateFormat (format);
		return formatter.parse(dateString);
	}
	public static String formatDate(Date date, String format){
		SimpleDateFormat formatter = new SimpleDateFormat(format);
		return formatter.format(date);
	}
	public static Date getCurrentTime(){
		return new Date();
	}
}
